package main

import (
	"fmt"
	"go.uber.org/zap"
	"os"
	"os/signal"
	"syscall"
	"user_srv/global"
	handler "user_srv/handler"
	"user_srv/initialize"
	proto "user_srv/proto"

	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/logger"
)

func main() {
	//初始化log
	initialize.InitLogger()
	//初始化数据库
	initialize.InitDB()

	//2 创建服务并注册到注册中心
	service := micro.NewService(
		micro.Name("user.srv"),
		micro.Version("latest"),
		micro.Registry(global.ConsulClient),
	)

	// 3 Register handler
	err := proto.RegisterUserSrvHandler(service.Server(), new(handler.User_srv))
	if err != nil {
		fmt.Println(err)
	}
	// 4 Run service
	if err := service.Run(); err != nil {
		logger.Fatal(err)
	}

	////接收终止信号 程序出现异常，终止
	quit := make(chan os.Signal)
	signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
	<-quit
	zap.S().Info("注销成功")

}
